// app.js
import websocket from './utils/websocket';

App({
  onLaunch() {
    // 获取本地存储的token
    const token = wx.getStorageSync('token');
    if (token) {
      // 如果有token，建立WebSocket连接
      websocket.connect();
    }

    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
  },
  globalData: {
    baseUrl: 'http://localhost:3000',
    userInfo: null,
    websocket: websocket  // 添加websocket到全局
  }
})
